
<div class="md-sidebar md-sidebar--primary" data-md-component="navigation">
  <div class="md-sidebar__scrollwrap">
    <div class="md-sidebar__inner">
      <nav class="md-nav md-nav--primary" data-md-level="0">

        <label class="md-nav__title md-nav__title--site">
            <a class="" href="{{ site.url }}{{ site.baseurl }}/" title="{{ site.title }}">
              <span class="md-nav__button md-logo">
                {{ site.title }}
              </span>
            </a>
        </label>

        <ul class="md-nav__list" data-md-scrollfix="">
          <li class="md-nav__item md-nav__item--active">
            <input class="md-toggle md-nav__toggle" data-md-toggle="toc" id="__toc" type="checkbox" />

            <nav class="md-nav md-nav--secondary">

                <a class="" href="{{ site.url }}{{ site.baseurl }}/" title="{{ site.title }}">
                  <label class="md-nav__title md-nav__title--site">
                    <span class="md-nav__button md-logo">
                      {{ site.title }}
                    </span>
                  </label>
                </a>

                <div class="md-nav__source">
                    <a class="md-source" data-md-source="github" href="{{ site.repo }}" title="Go to repository">
                    <span class="md-source__icon">
                        <i class="fa fa-github fa-3x"></i>
                    </span>
                    <span class="md-source__repository">
                      {{ site.github_user }}/{{ site.github_repo }}
                    </span></a>
                </div>

                <div class="md-nav__dropdown">
                  <select id="version-selector">
                    <!-- option value="#" selected="selected">v 0.5.1</option -->
                  </select>
                </div>

              <label class="md-nav__title" for="__drawer"></label>

              {% if page.sidebar %}

                <ul class="md-nav__list" data-md-scrollfix="">
                  {% assign paths = page.url | remove: "/docs/" | split: "/" %}
                  {% for section in site.data.toc %}
                  {% assign sectionpaths = section.url | remove: "docs/" | split: "/" %}
                  <li class="md-nav__item md-nav__item--nested navbar_bottom-border">
                    <a class="md-nav__link pancakes-parent-mobile"
                    id="pancakes-{{ section.title | slugify }}" title="{{ section.title }}">{{ section.title }}</a>
                    {% if section.children %}
                    <nav class="md-nav md-nav--secondary">
                      <a class="md-nav__title mobile-navbar-back" for="__toc">Table of contents</a>
                      <ul class="md-nav__list" data-md-scrollfix="">
                        {% for child in section.children %}
                        <li class="md-nav__item navbar_bottom-border">
                          <a class="md-nav__link" href="{{ site.baseurl }}/{{ child.url }}"
                              id="pancakes-{{ child.title | slugify }}"
                              title="{{ child.title }}">{{ child.title }}</a>
                        </li>
                        {% endfor %}
                      </ul>
                    </nav>
                    {% endif %}
                  </li>
                  {% endfor %}
                </ul>
            </nav>
          </li>

          <!-- This navigation is completely for mobile -->
          {% for section in site.data.toc %}<li class="md-nav__item mobile-nav" style="display:none">
            <a class="md-nav__link" title="{{ section.title }}">{{ section.title }}</a>
          </li>{% endfor %}

          <!-- This navigation is completely for non mobile -->
          {% assign paths = page.url | remove: "/docs/" | split: "/" | where_exp: "i", "i.size > 0" %}

         {% for section in site.data.toc %}
         {% assign sectionpaths = section.url | remove: "docs/" | split: "/" %}
         <li class="md-nav__item md-nav__item--nested not-mobile-nav invisible">
             <a class="md-nav__link pancakes-parent {% if sectionpaths.first == paths.first %}open-parent{% endif %}"
                id="pancakes-{{ section.title | slugify }}"
                title="{{ section.title }}">{{ section.title }}</a>
                {% if section.children %}
                <nav class="md-nav">
                    <ul class="md-nav__list">
                        {% for child in section.children %}
                        {% assign childs = child.url | remove: "docs/" | split: "/" %}
                        <li class="md-nav__item">
                        <a href="{% if child.external_url %}{{ child.external_url }}{% else %}{{ site.baseurl }}/{{ child.url }}{% endif %}"
                           title="{{ child.title }}" {% if sectionpaths.first != paths.first %}style="display:none;"{% endif %}
                           {% if childs.last == paths.last %} style="color: red;"{% endif %}
                           class="md-nav__link pancakes-child">{{ child.title }}</a>
                        </li>{% endfor %}
                    </ul>
                </nav>
                {% endif %}
         </li>
         {% endfor %}
         {% endif %}

        </ul>
      </nav>
    </div>
  </div>
</div>

{% if page.sidebar %}
<div class="md-sidebar md-sidebar--secondary invisible" data-md-component="toc">
  <div class="md-sidebar__scrollwrap">
    <div class="md-sidebar__inner">
      <nav class="md-nav md-nav--secondary">
        <label class="md-nav__title" for="__toc">Table of contents</label>
        <ul id="nav-toc" class="md-nav__list" data-md-scrollfix="">
        <!-- toc will be appended here!-->
        </ul>
        <a href="https://twitter.com/intent/tweet?original_referer={{ site.repo }}/edit/master/docs/src{{ page.path  | remove: "_docs"}}" title="Tweet this page" class="social-link"><i class="fa fa-twitter fa-1x"></i>Tweet this page</a>
        <a href="https://discourse.julialang.org/c/domain/probprog" title="Ask questions" class="social-link"><i class="fa fa-stack-overflow fa-1x"></i>Ask questions</a>
        <a href="{{ site.repo }}//issues/new?label=question&title=Question:&body=Question%20on:%20{{ site.repo }}/edit/master/docs/{{ page.path }}" title="Report issues" class="social-link"><i class="fa fa-comments fa-1x"></i>Report issues</a>
        <a href="{{ site.repo }}/edit/master/docs/src{{ page.path | remove: "_docs"}}" title="Edit this page on github"  class="social-link"><i class="fa fa-github fa-1x"></i> Edit me</a>
      </nav>
    </div>
  </div>
</div>
{% endif %}